#pragma once

#include <iostream>
#include <unistd.h>
#include <sys/epoll.h>
#include "Common.hpp"
#include "Log.hpp"

using namespace LogModule;

class Epoller
{
public:
    Epoller():_epfd(-1)
    {
        _epfd = epoll_create(128);
        if(_epfd < 0)
        {
            LOG(LogLevel::FATAL) << "epoll_create error!!!";
            exit(EPOLL_CREATE_ERR);
        }
        LOG(LogLevel::INFO) << "create epoll success: " << _epfd;
    }
    void AddEvent(int sockfd, uint32_t events)
    {
        struct epoll_event ev;
        ev.events = events;
        ev.data.fd = sockfd; // 细节哦！
        int n = epoll_ctl(_epfd, EPOLL_CTL_ADD, sockfd, &ev);
        if(n < 0)
        {
            LOG(LogLevel::ERROR) << "epoll_ctl error";
            return;
        }
        LOG(LogLevel::INFO) << "epoll_ctl success: " << sockfd;
    }
    void DelEvent()
    {}
    void ModEvent()
    {}
    void Wait()
    {}
    ~Epoller()
    {
        if(_epfd >= 0)
        {
            close(_epfd);
        }
    }
private:
    int _epfd;
};

// class Poll
// {

// };

// class Selector : public Poll
// {

// };

// class Poller: public Poll
// {

// };

// class Epoller: public Poll
// {

// };